using Godot;
using System;

public partial class Explosion : Node3D
{

	private GpuParticles3D debris;
	private GpuParticles3D smoke;
	private GpuParticles3D fire;
	private AudioStreamPlayer3D boomSound;
	
	public override void _Ready()
	{
		debris = GetNode<GpuParticles3D>("Debris");
		smoke = GetNode<GpuParticles3D>("Smoke");
		fire = GetNode<GpuParticles3D>("Fire");
		boomSound = GetNode<AudioStreamPlayer3D>("BoomSound");
		Explode();
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}

	public void Explode()
	{
		debris.Emitting = true;
		smoke.Emitting = true;
		fire.Emitting = true;
		boomSound.Play();
		var time = new Timer();
		AddChild(time);
		time.WaitTime = 2;
		time.Timeout += ExplodeEnd;
		time.Start();
	}

	private void ExplodeEnd()
	{
		QueueFree();
	}
}
